﻿namespace Chain.BLL
{
    using Chain.IDAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class MemCountDetail
    {
        private readonly Chain.IDAL.MemCountDetail dal = new Chain.IDAL.MemCountDetail();

        public bool Add(Chain.Model.MemCountDetail model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.MemCountDetail> DataTableToList(DataTable dt)
        {
            List<Chain.Model.MemCountDetail> list = new List<Chain.Model.MemCountDetail>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.MemCountDetail item = new Chain.Model.MemCountDetail();
                    if ((dt.Rows[i]["CountDetailID"] != null) && (dt.Rows[i]["CountDetailID"].ToString() != ""))
                    {
                        item.CountDetailID = int.Parse(dt.Rows[i]["CountDetailID"].ToString());
                    }
                    if ((dt.Rows[i]["CountDetailCountID"] != null) && (dt.Rows[i]["CountDetailCountID"].ToString() != ""))
                    {
                        item.CountDetailCountID = int.Parse(dt.Rows[i]["CountDetailCountID"].ToString());
                    }
                    if ((dt.Rows[i]["CountDetailGoodsID"] != null) && (dt.Rows[i]["CountDetailGoodsID"].ToString() != ""))
                    {
                        item.CountDetailGoodsID = int.Parse(dt.Rows[i]["CountDetailGoodsID"].ToString());
                    }
                    if ((dt.Rows[i]["CountDetailNumber"] != null) && (dt.Rows[i]["CountDetailNumber"].ToString() != ""))
                    {
                        item.CountDetailNumber = int.Parse(dt.Rows[i]["CountDetailNumber"].ToString());
                    }
                    if ((dt.Rows[i]["CountDetailDiscountMoney"] != null) && (dt.Rows[i]["CountDetailDiscountMoney"].ToString() != ""))
                    {
                        item.CountDetailDiscountMoney = decimal.Parse(dt.Rows[i]["CountDetailDiscountMoney"].ToString());
                    }
                    if ((dt.Rows[i]["CountDetailPoint"] != null) && (dt.Rows[i]["CountDetailPoint"].ToString() != ""))
                    {
                        item.CountDetailPoint = int.Parse(dt.Rows[i]["CountDetailPoint"].ToString());
                    }
                    if ((dt.Rows[i]["CountCreateTime"] != null) && (dt.Rows[i]["CountCreateTime"].ToString() != ""))
                    {
                        item.CountCreateTime = DateTime.Parse(dt.Rows[i]["CountCreateTime"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int CountDetailID)
        {
            return this.dal.Delete(CountDetailID);
        }

        public bool DeleteList(string CountDetailIDlist)
        {
            return this.dal.DeleteList(CountDetailIDlist);
        }

        public bool Exists(int CountDetailID)
        {
            return this.dal.Exists(CountDetailID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public int GetMaxId()
        {
            return this.dal.GetMaxId();
        }

        public DataSet GetMemCountList(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetMemCountList(PageSize, PageIndex, out resCount, strWhere);
        }

        public Chain.Model.MemCountDetail GetModel(int CountDetailID)
        {
            return this.dal.GetModel(CountDetailID);
        }

        public List<Chain.Model.MemCountDetail> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public DataSet GetQueryMemCountList(string strWhere)
        {
            return this.dal.GetQueryMemCountList(strWhere);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public bool Update(Chain.Model.MemCountDetail model)
        {
            return this.dal.Update(model);
        }

        public int UpdateCountDetailNumber(int intNumber, int intCountDetailID)
        {
            return this.dal.UpdateCountDetailNumber(intNumber, intCountDetailID);
        }
    }
}

